<template>
  <div class="home">
    <el-container>
      <el-aside width="200px" >
        <el-menu
          background-color="rgb(51, 54, 66)"
          text-color="white"
          @select="onClickSelect"
           :collapse="isCollapse"
        >
          <el-submenu
            v-for="(item, index) in menus"
            :key="index"
            :index="String(index)"
          >
            <template slot="title"
              ><i :class="item.icon"></i>{{ item.menuName }}</template
            >
            <el-menu-item
              v-for="(subItem, subIndex) in item.subMenus"
              :index="`${index}-${subIndex}`"
              :key="subIndex"
            >
              {{ subItem.subMenuName }}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-main>
        <div class="home-header-container">
          <div class="home-left-hide">
            <i class="el-icon-s-fold" style="font-size:30px;color:white" @click="onClickHide"></i>
          </div>
          <div class="home-right-out">
                <el-button type="info" round @click="onClickOut">退出登录</el-button>
          </div>
        </div>
        <div class="home-content-container">
            <router-view></router-view>
        </div>  
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  components: {},
  data() {
    return {
      menus: [],//保存导航菜单
      isCollapse:false,
    };
  },
  methods:{
    //退出登录按钮 
    onClickOut(){
      window.localStorage.removeItem("token");
      this.$router.push("/login");
    },
    
    //导航条
    onClickSelect(index,indexPath){
      console.log(index,indexPath);
      var path=""
      switch(index){
        case "0-0": path="/home"; break;
        case "1-0": path="/order"; break;
        case "2-0": path="/user"; break;
        case "2-1": path="/menu"; break;
        case "2-2": path="/role"; break;
        case "2-3": path="/company"; break;
        // case "1-5": path="/XTong"; break;
        // case "1-6": path="/QXian"; break;
        // case "1-7": path="/ZFu"; break;
        default: path="/"; break
      }
      this.$router.push(path);
    },

    //隐藏按钮
    onClickHide(){
      this.isCollapse=!this.isCollapse
    }
  },

  mounted() {
    this.$axios.get("http://localhost:8080/menus.json").then((res) => {
      this.menus = res.data;
    });
  },

};
</script>

<style scoped>
* {
  margin: 0px;
  padding: 0px;
}
.home {
  width: 100%;
  height: 95vh;
}
.el-aside {
  height: 95vh;
  background-color: rgb(51, 54, 66);
  color: #333;
  text-align: center;
  /* line-height: 200px; */
}

.el-main {
  height: 95vh;
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  /* line-height: 160px; */
}
/*   
  body > .el-container {
    margin-bottom: 40px;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  } */
.home-header-container {
  width: 100%;
  background-color: rgb(51, 54, 66);
  height:64px;
  position: relative;
}
.home-left-hide{
  width:70px;
  height:64px;
  position: absolute;
  left:0px;
  /* background-color: aquamarine; */
  display: inline-flex;
  justify-content: center;
  align-items:center;
}
.home-right-out{
  width:100px;
  height:64px;
  display:inline-flex;
  justify-content: center;
  align-items: center;
  /* background-color: lightgreen; */
  position: fixed;
  position: absolute;
  top:0px;
  right:20px;
  font-size:13px;
}
.home-content-container{
  position: fixed;
  top:75px;
  width:84%;
  height:90vh;
  /* background-color: lightpink; */
}
</style>
